<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="java.sql.*" %>
        <%@ include file="connstring.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主页</title>
</head>
<title>收货地址管理列表</title>
</head>
<style>
*{
margin:0;
padding:0;
text-decoration:none;
color:black;
border:0;
}
body{
font-family:微软雅黑;
text-decoration:none;
background:rgba(240, 240, 240, 0.4);
 font-size:17px;
 
}
.box{
  text-align:center;
  color:black;
  font-size:30px;
  padding-bottom:30px;
}
table tr{
border:0;
}
table tr td{
color:black;
width:150px;
height:70px;
 border:0;
border-bottom:1px dashed #000;
text-align:center;
}
table tr td:hover{
color:#900000;
}
table tr td a:hover{
color:#900000;
}
table tr th{
color:#fff;
background:#900000;
height:90px;
border:0;
}
.shuzi{
display:inline-block;
width:25px;
height:25px;
background:rgba(0,0,0,0);
}
.shuzi a{
padding-left:6px;
text-align:center;
}
.shuzi:hover{
background:#aa0000;
border-radius:50%;
}
</style>
<body>
<h2 class="box">用户收货地址管理列表</h2>

<%!
int getRecordCount(String sql,String valueField,String driver,String url){
	
int returnValue=0;
Connection conn=null;
ResultSet rs =null;
Statement stmt=null;
try{
	Class.forName(driver);
	conn= DriverManager.getConnection(url);	
	 stmt=conn.createStatement();
	rs=stmt.executeQuery(sql);
	if(rs.next()){
		returnValue=rs.getInt(valueField);
	}
}
catch(Exception ex){
}
finally{
	try{if(rs!=null)  rs.close();
	}
	catch(SQLException ex){
		
	}
	try{if(conn!=null) conn.close();
	}
	catch(SQLException ex){
		
	}
	try{if(stmt!=null)  stmt.close();
	}
	catch(SQLException ex){
		
	}
}     
 return returnValue;
}
 %>
 <%
 String strPageNo=request.getParameter("page");
 if(strPageNo==null)   strPageNo="1";
 int Pagesize=10;
 int curPage=Integer.parseInt(strPageNo);
 int recordCount=getRecordCount("select count(id)  as tiaoshu from three_user","tiaoshu",driver,url);
 int totalPage;
 if(recordCount%Pagesize==0){
	 totalPage=recordCount/Pagesize;
 }
 else{
	 totalPage=recordCount/Pagesize+1;
 }
 int startPos=Pagesize*(curPage-1);
 
 Connection conn=null;
 ResultSet rs =null;
 Statement stmt=null;
 try{
 	Class.forName(driver);
 	conn= DriverManager.getConnection(url);	
 	 stmt=conn.createStatement();
 	 String sql="select * from  three_user order by id asc limit "
 			 +startPos+","+Pagesize+";";
 	rs=stmt.executeQuery(sql);
 	
 %>
 <table width="100%" border="1"  cellspacing="0" cellpadding="5">
 <tr>
  <th>id</th>
  <th>姓名</th>
   <th>手机号码</th>
     <th>市</th>
    <th>详细地址</th>
     <th>默认地址</th>
    <th>添加</th>
  <th>编辑</th>
  <th>删除</th>
 </tr>
 
 <% 
   while(rs.next()){
 %>
   <tr>
  <td><%=rs.getString("id")%></td>
  <td> <%=rs.getString("name")%></td>
  <td><%=rs.getString("phone")%></td>
  <td><%=rs.getString("city")%></td>
   <td><%=rs.getString("address")%></td>
     <td><%=rs.getString("remark")%></td>
    <td><a   href="addressadd.jsp"  >添加</a></td>
  <td><a   href="newsedit.jsp?name=<%=rs.getString("name")%>"  >修改</a></td>
  <td><a   href="newsdel.jsp?name=<%=rs.getString("name")%>"
   onclick="return confirm('您确定要删除吗?');">删除</a></td>
  </tr>
 <%
   }
 %>
 </table>
 <div  class="page">
 <%
 for(int i=1;i<=totalPage;i++){
	 if(curPage==i){
		 out.print(i+"&nbsp;");
	 }
	 else{
%>
<span class="shuzi"><a href="newslist.jsp?page=<%=i%>"><%=i%></a></span>	
<%	 
	 }
 }
 %>

 <span>[共<%=totalPage %>页,每页<%=Pagesize %>条,共<%=recordCount %>条]</span>
 </div>
<%
 }
 catch(Exception ex){
		out.print("错误："+ex.getMessage());
	}
	finally{
		if(rs!=null)  rs.close();
		if(conn!=null)  conn.close();
		if(stmt!=null)  stmt.close();
		
	}     
%>
 
</body>

</html>